package com.blockchain.console.servlets.common;

import java.math.BigDecimal;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.console.service.common.IndexManage;
import com.blockchain.console.service.common.entity.IndexCount;
import com.blockchain.console.servlets.AbstractConsoleServlet;
import com.blockchain.framework.service.ServiceSession;

public class Index extends AbstractConsoleServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void processGet(HttpServletRequest request,
			HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		processPost(request, response, serviceSession);
	}

	@Override
	protected void processPost(HttpServletRequest request,
			HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		IndexManage index = serviceSession.getService(IndexManage.class);
		IndexCount indexCount = index.getIndexCount();
		boolean isOneLogin = index.isOneLogin();
		BigDecimal btcTotal = index.getBtcTotal().setScale(2, BigDecimal.ROUND_HALF_UP);
		BigDecimal tradeTotal = index.getTradeTotal().setScale(2, BigDecimal.ROUND_HALF_UP);
		BigDecimal articalTotal = index.getArticalTotal().setScale(2, BigDecimal.ROUND_HALF_UP);
		request.setAttribute("btcTotal", btcTotal);
		request.setAttribute("tradeTotal", tradeTotal);
		request.setAttribute("articalTotal", articalTotal);
		
		request.setAttribute("indexCount", indexCount);
		request.setAttribute("isOneLogin", isOneLogin);
		forwardView(request, response, Index.class);
	}

}
